<?php 
include('./fun.php');include('./hd_fun.php');
$conn=my_sql($cfg);
$re=user_login();
if($re['err']=='no_login'){direct('login.php?t='.time());exit;}
if($re['err']!='ok'){die($re['err']);}
$user=$re['user'];
$shop_id=$re['shop_id'];
$shop=get_shop();
$set=get_set();

if($user['shop_id']==$shop['id']){$is_adm=1;}

$sql='select * from '.$cfg['e'].'img where shop_id="'.$shop['id'].'" ';
$page=g('page');if(!$page){$page=1;}
$page_num=24;$start=($page-1)*$page_num;
$sql.=' order by id desc limit '.$start.','.$page_num;
$l=db($sql);
if($l){
foreach($l as $v){
if($v['url']){
$img=$v['url'];
}else{
$v['img']=$v['id'].'|'.$v['ext'];
$img=get_img($v['img'],'_240');
}

$h.='<img_item id="item_'.$v['id'].'">
<imgx style="background:url('.$img.') no-repeat center;background-size:cover;">
<img_is_select></img_is_select>
<icon class="icon icon-square" onclick="select_this_img($(this))" i="'.$v['id'].'"></icon>
<span>'.($v['path']?$v['path']:'未分类').'</span>
</imgx>

</img_item>';


}


}


?>
<style>
img_list{float:left;width:100%;height:100%;}
img_list{float:left;width:100%;height:100%;padding-top:10px}
img_list img_item{float:left;width:12.5%;padding:5px;height:160px}
img_list imgx{float:left;width:100%;height:100%;}
img_list item{float:left;width:100%;height:100%;}
img_list span{position:absolute;width:100%;height:30px;text-align:center;line-height:30px;bottom:0;left:0;background:rgba(0,0,0,0.5);color:#fff;font-size:12px;overflow:hidden;}
img_list item img{float:left;width:100% !important;height:100%;}
img_is_select{position:absolute;width:100%;height:100%;background:rgba(0,0,0,0.5);left:0top:0;z-index:100;display:none;}
.is_select img_is_select{display:block;}
img_list icon{position:absolute;top:10px;right:10px;font-size:30px !important;color:#999;z-index:100}
img_list .icon-squarecheckfill{color:crimson;}

</style>

<bbx>
<hh><b>图库管理</b></hh>
<mm>
<index><a class="m b" onclick="$('#up_img').click()">图片上传</a>
<a>京东图片获取</a>
<xx style="display:none;">
<a class="m" onclick="c_win_show($(this))">设置分类</a>
<a class="m red" onclick="del_all($(this))">删除</a>
</xx>

</index>

<img_list>
<?php echo $h;?>
<?php page();?>
</img_list>
</mm>



</bbx>


<script>
function select_this_img(o){
var id=o.attr('i');
var obj=$('#item_'+id);
var s=obj.hasClass('is_select');
if(!window.data){window.data={}}
if(s){
o.removeClass('icon-squarecheckfill');
o.addClass('icon-square');
obj.removeClass('is_select');
delete(window.data['item_'+id]);
}else{
o.addClass('icon-squarecheckfill');
o.removeClass('icon-square');
obj.addClass('is_select');
window.data['item_'+id]=id;
}
console.log(window.data,Object.keys(window.data).length);
if(Object.keys(window.data).length>0){
$('index xx').show();
}else{
$('index xx').hide();
}
}

function c_win_show(){
var h='<l><text>分类名称</text><input placeholder="请输入分类名称" style="" id="c"></l>';
h+='<l><a class="blue" onclick="set_c($(this))">设置分类</a></l>';
win({title:'设置分类',width:600,html:h})
}

function set_c(){
var val=$('#c').val();
if(!val){msg('请输入分类');return;}
if(!window.data){msg('请选择图片');return;}
if(Object.keys(window.data).length==0){msg('请选择图片');return;}
var id='';
for(var i in window.data){
id+=window.data[i]+','
}
var d={path:val,id:id}
post('img_set_c',d,'',function(res){
$('win').remove();
window.data={};
$('index xx').hide();
main_load();
});

}

function del_all(){
if(!window.data){msg('请选择图片');return;}
if(Object.keys(window.data).length==0){msg('请选择图片');return;}
var id='';
for(var i in window.data){
id+=window.data[i]+','
}
if(!confirm("删除将无法恢复，是否继续?")){return;}
var d={id:id}
post('img_del',d,'',function(res){
   main_load();
   msg('删除成功');
});
}





</script>